<template>
  <div class="book-detail-container">
    <div class="book-area">
      <div class="book-cover">
        <img :src="bookImgUrl" :onerror="errorImage" />
      </div>
      <div class="book-info">
        <div class="book-h2">{{ bookName }}</div>
        <div class="book-author">{{ author }}</div>
        <div class="book-pp">出版社：{{ publisher }}</div>
        <div class="book-pp">主题：{{ subject }}</div>
        <div class="book-pp">ISBN：{{ isbn }}</div>
      </div>
    </div>
    <div class="book-evaluate">
      <div class="book-eli">
        <img v-if="!collect" @click="collectFunc" src="@/assets/images/icon-star.png"/>
        <img v-else @click="collectFunc" src="@/assets/images/icon-star-active.png"/>
        <p>收藏</p>
      </div>
      <div class="book-eli">
        <img src="@/assets/images/icon-eye.png"/>
        <p>浏览 {{ browse }}</p>
      </div>
      <div class="book-eli">
        <img src="@/assets/images/icon-borrow.png"/>
        <p>借阅 {{ borrow }}</p>
      </div>
    </div>
    <!-- 摘要 -->
    <div class="abstract-box">
      <h2>摘要</h2>
      <div :class="!requireAll?'abstract-con':'abstract-con-show'">
        <div ref="abstractBg" class="abstract-bg"></div>
        <span ref="abstractText" class="abstract-con-text" :class="isToggle && !requireAll?'elips':'strech'">{{ abstract }}</span>
      </div>
      <div v-if="isToggle" class="more-text" @click="moreText">
        <span v-if="!requireAll">展开</span>
        <span v-else>收起</span>
      </div>
    </div>
    <!-- 馆藏 -->
    <div class="collection-area">
      <div class="collec-number">在馆{{ collecIn }}/馆藏{{ collecAll }}</div>
      <div class="collec-ul">
        <div v-for="(item, index) in collecShow" :key="index" class="collec-li">
          <div class="collec-upcon">
            <div v-if="item.inner" class="collec-state active">
              <i></i>
              <span>在馆</span>
            </div>
            <div v-else class="collec-state">
              <i></i>
              <span>借出</span>
            </div>
            <div class="collec-title">
              <h2>{{ item.libName }}</h2>
              <div class="collec-address">
                <span>{{ item.distance }}</span>
              </div>
            </div>
          </div>
          <ul class="collec-info">
            <li>
              <label>条码号：</label>
              <span class="wordone">{{ item.barCode }}</span>
            </li>
            <li>
              <label>所属地点：</label>
              <span class="textBlue wordone">{{ item.address }}</span>
            </li>
            <li>
              <label>索书号：</label>
              <span class="wordone">{{ item.callno }}</span>
            </li>
            <li>
              <label>流通类型：</label>
              <span class="wordone">{{ item.type }}</span>
            </li>
          </ul>
        </div>
      </div>
      <div v-if="morecon" @click="collecMore" class="moreBtn">展开更多</div>
    </div>
    <!-- 推荐好书 -->
    <div class="recommend-book">
      <div class="recommend-title">相似图书</div>
      <div class="recommend-nav">
        <div v-for="(item, index) in recommendBook" :key="index" class="recommend-li">
          <div class="recommend-img">
            <img :src="item.imgurl" :onerror="errorImage" />
          </div>
          <div class="recommend-name">{{ item.title }}</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'BookDetail',
  data () {
    return {
      bookImgUrl: '',
      bookName: '三国演义',
      author: '施耐庵',
      publisher: '上海文艺出版社',
      subject: '古典名著',
      isbn: '8998123875398',
      collect: false,
      browse: 18,
      borrow: 76,
      requireAll: false,
      isToggle: false,
      abstract: '《三国演义》语言流畅，雅俗共赏，全书结构严谨，借鉴编年史的手法，将百年间错综复杂的历史事件和层出不穷的历史人物串联起来，叙述有条不紊，浑然一体，“温酒斩华雄”“过五关斩六将”“威震长坂桥”“单骑救主”“空城计”等故事更是广为流传，家喻户晓。',
      collecIn: 4,
      collecAll: 18,
      collecList: [
        {
          inner: false,
          libName: '长沙市图书馆',
          distance: '1km',
          barCode: '12u3098973874',
          address: '长沙市北城三角洲',
          callno: '20898901',
          type: '中文图书'
        },
        {
          inner: true,
          libName: '长沙市图书馆',
          distance: '1km',
          barCode: '12u3098973874',
          address: '长沙市北城三角洲',
          callno: '20898901',
          type: '中文图书'
        },
        {
          inner: false,
          libName: '长沙市图书馆',
          distance: '1km',
          barCode: '12u3098973874',
          address: '长沙市北城三角洲',
          callno: '20898901',
          type: '中文图书'
        },
        {
          inner: true,
          libName: '长沙市图书馆',
          distance: '1km',
          barCode: '12u3098973874',
          address: '长沙市北城三角洲',
          callno: '20898901',
          type: '中文图书'
        },
        {
          inner: false,
          libName: '长沙市图书馆',
          distance: '1km',
          barCode: '12u3098973874',
          address: '长沙市北城三角洲',
          callno: '20898901',
          type: '中文图书'
        },
        {
          inner: true,
          libName: '长沙市图书馆',
          distance: '1km',
          barCode: '12u3098973874',
          address: '长沙市北城三角洲',
          callno: '20898901',
          type: '中文图书'
        },
        {
          inner: false,
          libName: '长沙市图书馆',
          distance: '1km',
          barCode: '12u3098973874',
          address: '长沙市北城三角洲',
          callno: '20898901',
          type: '中文图书'
        },
        {
          inner: true,
          libName: '长沙市图书馆',
          distance: '1km',
          barCode: '12u3098973874',
          address: '长沙市北城三角洲',
          callno: '20898901',
          type: '中文图书'
        }
      ],
      collecShow: [],
      morecon: true,
      recommendBook: [
        {
          imgurl: '',
          title: '西游记'
        },
        {
          imgurl: '',
          title: '红楼梦'
        },
        {
          imgurl: '',
          title: '水浒传'
        },
        {
          imgurl: '',
          title: '西游记'
        },
        {
          imgurl: '',
          title: '红楼梦'
        },
        {
          imgurl: '',
          title: '水浒传'
        }
      ],
      errorImage: 'this.src="' + require('@/assets/images/default-book-image.jpg') + '"'
    }
  },
  created () {
    document.title = this.bookName
  },
  mounted () {
    this.collectionNumber(5)
    this.judgeOpenMore()
  },
  methods: {
    collectFunc () {
      this.collect = !this.collect
    },
    // 判断是否展开摘要
    judgeOpenMore () {
      var infoWrapperHeight = this.$refs.abstractBg.offsetHeight
      var conWrapperHeight = this.$refs.abstractText.offsetHeight
      var isToggle = infoWrapperHeight <= conWrapperHeight
      this.isToggle = isToggle
    },
    moreText () {
      this.requireAll = !this.requireAll
    },
    collecMore () {
      this.collectionNumber(5)
    },
    collectionNumber (num) {
      var collecShow = this.collecShow
      var collecList = this.collecList
      var morecon = false
      if (collecList.length / num > 1) {
        morecon = true
      }
      collecShow = collecShow.concat(collecList.splice(0, num))
      this.collecList = collecList
      this.collecShow = collecShow
      this.morecon = morecon
    }
  }
}
</script>
<style lang="scss" scoped>
.book-area {
  height: 3.48rem;
  display: flex;
  margin: 0 .17rem;
  padding-top: .30rem;
}

.book-cover {
  width: 2.70rem;
  height: 2.70rem;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

.book-cover img {
  height: 100%;
}

.book-info {
  width: 4.48rem;
  padding-left: .24rem;
}

.book-info div {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-h2 {
  font-size: .34rem;
  line-height: .68rem;
}

.book-author {
  font-size: .28rem;
  color: #666;
  padding: .16rem 0;
}

.book-pp {
  font-size: .28rem;
  color: #333;
  line-height: .42rem;
}

.book-evaluate {
  height: .86rem;
  margin: 0 .17rem;
  padding: 0 .40rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid #d8d8d8;
  border-bottom: 1px solid #d8d8d8;
}

.book-eli {
  font-size: .28rem;
  color: #333;
  display: flex;
  align-items: center;
}

.book-eli img {
  width: .40rem;
  height: .40rem;
  margin-right: .20rem;
}

.abstract-box {
  margin: 0 .17rem;
}

.abstract-box h2 {
  font-size: .34rem;
  padding: .26rem 0 .16rem;
}

.abstract-con {
  overflow: hidden;
  position: relative;
}

.abstract-con-show {
  height: auto;
  position: relative;
}

.abstract-bg {
  width: 100%;
  height: 1.76rem;
  position: absolute;
  left: 0;
  top: 0;
}

.abstract-con-text {
  font-size: .26rem;
  color: #333;
  line-height: .44rem;
  text-align: justify;
  position: relative;
}

.elips {
  display: -webkit-box;
  line-clamp: 4;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  height: 1.76rem;
  overflow: hidden;
}

.strech {
  display: block;
  height: auto;
}

.more-text {
  font-size: .26rem;
  color: #2081bf;
  text-align: right;
}

.collection-area {
  background: #f5f8fa;
  padding: .17rem;
  margin-top: .20rem;
}

.collec-number {
  line-height: .76rem;
  font-size: .28rem;
  color: #333;
}

.collec-ul {
  position: relative;
}

.collec-li {
  margin-bottom: .20rem;
  background: #fff;
  border-radius: .08rem;
  box-shadow: 0 .02rem .16rem rgba(0, 0, 0, 0.12);
}

.collec-upcon {
  height: .84rem;
  display: flex;
}

.collec-state {
  width: 1.56rem;
  font-size: .32rem;
  color: #666;
  padding-left: .24rem;
  display: flex;
  align-items: center;
  border-right: 1px solid #d8d8d8;
}

.collec-state i {
  width: .16rem;
  height: .16rem;
  border-radius: 50%;
  background: #666;
  margin-right: .08rem;
}

.collec-state.active {
  color: #22ac38;
}

.collec-state.active i {
  background: #22ac38;
}

.collec-title {
  width: 5.60rem;
  padding: 0 .24rem 0 .10rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 1;
}

.collec-title h2 {
  width: 3.30rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: .32rem;
  color: #0e2045;
}

.collec-address {
  font-size: .26rem;
  color: #908693;
  display: flex;
  align-items: center;
}

.collec-address image {
  width: .60rem;
  height: .60rem;
  margin-left: .16rem;
}

.collec-info {
  display: flex;
  flex-wrap: wrap;
}

.collec-info li {
  font-size: .26rem;
  width: 50%;
  height: .60rem;
  line-height: .60rem;
  padding: 0 .12rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  border-right: 1px solid #d8d8d8;
  border-top: 1px solid #d8d8d8;
}

.collec-info li:nth-child(2n) {
  border-right: none;
}

.textBlue {
  font-size: .26rem;
  color: #2b62cc;
}

.wordone {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.moreBtn {
  height: .80rem;
  line-height: .80rem;
  text-align: center;
  font-size: .28rem;
  color: #fff;
  background: #0fbcfd;
  border-radius: .08rem;
  box-shadow: 0 .02rem .16rem rgba(0, 0, 0, 0.12);
}

.recommend-book {
  position: relative;
}

.recommend-title {
  font-size: .34rem;
  padding: .36rem .17rem .26rem;
}

.recommend-navcon {
  width: 100%;
  overflow: hidden;
}

.recommend-nav {
  white-space: nowrap;
  overflow: scroll;
}

.recommend-li {
  width: 1.86rem;
  display: inline-block;
  margin: 0 .08rem .20rem;
}

.recommend-li:nth-child(1) {
  margin-left: .17rem;
}

.recommend-li:last-child {
  margin-right: .17rem;
}

.recommend-img {
  width: 1.86rem;
  height: 1.86rem;
  border-radius: .05rem;
  border: 1px solid #eee;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

.recommend-img img {
  height: 100%;
}

.recommend-name {
  font-size: .24rem;
  line-height: .32rem;
  color: #444;
  text-align: center;
  margin-top: .10rem;
}

.gloveb-label {
  display: flex;
  margin-top: .06rem;
}

.gloveb-label div {
  height: .36rem;
  line-height: .36rem;
  border-radius: .06rem;
  font-size: .22rem;
  padding: 0 .14rem;
  margin-right: .04rem;
}

.gloveb-label .black-label {
  background: #d6d2d2;
  color: #0e0d0d;
}

.gloveb-label .green-label {
  background: #b4ffe7;
  color: #23b0b9;
}
</style>
